#!/bin/bash
##这是为服务安装一条路服务的脚本整合
#最小化实现Docker安装
mirrors_selects(){
    if [[ "$source_select" == 'y' || "$source_select" == 'Y' ]];then
        source_menu__mirrors_select "$1" "$2"
    fi
}
install_menu__install_docker_ce_mini(){
    service_chek 'docker' 
    if [[ "$Not_config_source" == 'y' ]];then
        green_zt "跳过源配置"
    else
        source_${Package_managements}_bak #检测源备份

        mirrors_selects  "系统源" "mirrors_os"
        mirrors_selects  "Docker源" "mirrors_docker"
        if [[ "$Package_managements" == 'apt' ]];then
            source_${Package_managements}_${System_Type}
        else
            source_${Package_managements}_${System_Type}${System_version}
        fi
        source_${Package_managements}_docker-ce
        source_config='y'
    fi
    install_docker__ce__install_docker #安装Docker
    
    install_docker__ce__docker_config #配置Docker
}

#最小化实现K8S安装
install_menu_install_k8s_mini(){
    if [[ "$Package_managements" == 'yum' ]];then
         disable_firealld #关闭(卸载)防火墙及SELINUX
    fi
    #Not_config_source检测是否需要配置相关源
    if [[ "$Not_config_source" == 'y' ]];then
        green_zt "跳过源配置"
    else
        if [[ "$source_config" == 'y' ]];then
            green_zt "跳过系统源配置"
        else
            source_${Package_managements}_bak #检测源备份

            #获取用户选择的镜像站,一参是备注，二参是设置一个变量名
            mirrors_selects "系统源" "mirrors_os"
            source_${Package_managements}_${System_Type}${source_version} #配置系统源
        fi
        mirrors_selects "配置K8S源"   "mirrors_k8s"

        source_${Package_managements}_k8s #配置K8S源
    fi
    install_k8s_all
}
install_menu__install_docker_ce_k8s(){
    #安装Docker
    install_menu__install_docker_ce_mini 'k8s'

    install_menu_install_k8s_mini #安装K8S
}
#完成初始的数据库服务安装
install_menu__mariadb_install(){
    service_chek 'mariadb-server' #检测是否已经安装该服务
    #Not_config_source检测是否需要配置相关源
    if [[ "$Not_config_source" == 'y' ]];then
        green_zt "跳过源配置"
    else
        install_mariadb-info-set #设置/检查安装信息

        source_${Package_managements}_bak #检测源备份
    
        source_${Package_managements}_${System_Type}${source_version}   #配置系统源

        source_menu-mariadb_version-select #选择Mariadb源版本

        source_mariadb-${Package_managements} #配置Mariadb源
    fi

    install_mariadb-install #安装服务

    install_mariadb-init #初始化数据库
}
install_menu_install_Harbor(){
    install_menu__install_docker_ce_mini #安装Docker

    install_docker_ce__docker_compose #安装docker-compose

    install_docker_harbor #安装harbor
}
install_menu_install_openstack_base(){
    #获取安装配置
    if  [[ ! -e "/opt/installer.sh" ]];then
        config_openstack_installer_mode
    else
        source /opt/installer.sh
    fi
    #获取当前节点类型并配置主机名
    shell_openstaack_Q_install_host_config


    #配置系统环境
    disable_firealld #关闭(卸载)防火墙及SELINUX
    if [[ "$Not_config_source" == 'y' ]];then
        green_zt "跳过源配置"
    else
        source_${Package_managements}_${System_Type}${source_version}   #配置系统源

        source_yum_openstack_queens #配置Openstack源

        #source_mariadb-${Package_managements} #配置数据库源
    fi

    shell_openstaack_Q_install_service_install_base #安装基础环境
    echo -e "\nopenstack_base=y" >> /opt/installer.sh
}
install_menu_install_openstack(){
    if [[ -e '/opt/installer.sh' ]];then
        source /opt/installer.sh
    fi
    if [[ "$openstack_base" == 'y' ]];then
        if [[ -e "/opt/installer.sh" ]];then
            source /opt/installer.sh
        else
            red_z_green_z "找不到安装参数脚本:[ /opt/installer.sh ]" "已重新进入环境配置程序"
            install_menu_install_openstack_base
        fi
        local_name=`hostname`
        if [[ "$local_name" == "$HOST_NAME" ]];then
            Entering "控制节点组件安装-->"
            shell_openstaack_Q_install_install_openstack_controller
        elif [[ "$local_name" == "$NODE_HOST_NAME" ]];then
            Entering "计算节点组件安装-->"
            shell_openstaack_Q_install_install_openstack_compute
        fi
    else
        install_menu_install_openstack_base
    fi
}